<template>
  <div class="register">
    <van-nav-bar title="嗨购商城" left-arrow @click-left="onClickLeft" />

    <van-form @submit="onSubmit">
      <van-cell-group>
        <van-field
          v-model="pass"
          label="设置密码"
          name="pass"
          placeholder="请输入您的密码.."
        >
        </van-field>
      </van-cell-group>
      <div style="margin: 16px">
        <van-button
          round
          block
          color="red"
          :disabled="!flag"
          native-type="submit"
        >
          注册
        </van-button>
      </div>
    </van-form>
  </div>
</template>
<script setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import { dofinishregister } from "@/api/user.js";
const router = useRouter();
const onClickLeft = () => history.back();
const pass = ref("");
const flag = computed(() => /^\d{6}$/.test(pass.value));
const onSubmit = (user) => {
  //    console.log(user);
  dofinishregister({
    tel: localStorage.getItem("tel"),
    password: pass.value,
  }).then(({ data: res }) => {
    //    console.log(res);
    if (res.code != 200) {
      showFailToast("注册失败");
      return;
    }
    router.go(-3);
    // 跳转到登录页
    // router.push()
  });
};
</script>

<style>
</style>